package com.lq.demo.demo.mode.timer.quartz;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.Trigger;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Auther: LQ
 * @Date: 2018/10/15 22:31
 * @Description:
 */
@Slf4j
@Data
public class HelloJob implements Job {

    private String triggerkey;


    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        //需要定时处理的业务逻辑类

        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = simpleDateFormat.format(date);
        log.info("-------------------------");
        log.info("execute time is {}",time);
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Trigger currentTrigger = context.getTrigger();
        Date startTime = currentTrigger.getStartTime();
        Date endTime = currentTrigger.getEndTime();
        log.info("start time is {}", startTime);
        log.info("end  time is {}", endTime);
        /*log.info("the time is {}", time);
        log.info("hello world quartz!!!");
        String indenty = context.getJobDetail().getKey().getGroup() + context.getJobDetail().getKey().getName();
        log.info("indenty {}", indenty);
        String indentyOfTrigger = context.getTrigger().getKey().getGroup() + context.getTrigger().getKey().getName();
        log.info("indentyOfTrigger {}", indentyOfTrigger);
        Object code = context.getJobDetail().getJobDataMap().get("code");
        log.info("code is {}", code);
        Object triggerkey = context.getTrigger().getJobDataMap().get("triggerkey");
        log.info("triggerkey {}", triggerkey);
        //这个是quartz框架自动赋值的
        log.info("triggerkey2  {}", triggerkey);*/
        log.info("-------------------------");

    }
}
